﻿using log4net;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Test.Common.Log;

namespace Test.Log.Log4Net
{
    public class Log4NetLogger : ILogger
    {

        private ILoggerManager logManager;
        private readonly ILog log;

        public Log4NetLogger(ILoggerManager logManager, ILog log)
        {
            this.logManager = logManager;
            this.log = log;
        }
        public void Log(LogLevel level, IFormatProvider formatProvider, string message, params object[] args)
        {
            switch (level)
            {
                case LogLevel.Error:
                    if (logManager.IsLogLevelEnabled(LogLevel.Error))
                    {
                        log.ErrorFormat(formatProvider, message, args);
                    }
                    break;
                case LogLevel.Fatal:
                    if (logManager.IsLogLevelEnabled(LogLevel.Fatal))
                    {
                        log.FatalFormat(formatProvider, message, args);
                    }
                    break;
                case LogLevel.Info:
                case LogLevel.Trace:
                    if (logManager.IsLogLevelEnabled(LogLevel.Info))
                    {
                        log.InfoFormat(formatProvider, message, args);
                    }
                    break;
                case LogLevel.Warn:
                    if (logManager.IsLogLevelEnabled(LogLevel.Warn))
                    {
                        log.WarnFormat(formatProvider, message, args);
                    }
                    break;
                case LogLevel.Debug:
                    if (logManager.IsLogLevelEnabled(LogLevel.Debug))
                    {
                        log.DebugFormat(formatProvider, message, args);
                    }
                    break;
            }
        }
    }
}
